/**
 * 通用的返回JSON数据的结构s
 * Created by zhanggj
 * At 2013-4-12
 */
package com.chouxiaozi.wechatpublic.commons;
import com.chouxiaozi.wechatpublic.commons.util.JsonUtil;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

public class JsonResult {
	private int retcode; // 状态码
	private String retmsg; // 消息
	private Object retdata; // 返回的数据
	
	public JsonResult() {
		
	}
	
	public JsonResult(int retcode, String retmsg, Object retdata) {
		this.retcode = retcode;
		this.retmsg = retmsg;
		this.retdata = retdata;
	}

	public int getRetcode() {
		return retcode;
	}

	public void setRetcode(int retcode) {
		this.retcode = retcode;
	}

	public String getRetmsg() {
		return retmsg;
	}

	public void setRetmsg(String retmsg) {
		this.retmsg = retmsg;
	}

	public Object getRetdata() {
		return retdata;
	}

	public void setRetdata(Object retdata) {
		this.retdata = retdata;
	}
	
	/**
	 * 转换成json格式
	 * @return
	 */
	public String asJson() {
		try {
			return JsonUtil.writeJson(this);
		} catch(Exception e) {
			e.printStackTrace();
			return "{}";
		}
	}
	
	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}
}
